package mj.scott.back.user.service.impl;

import lombok.extern.slf4j.Slf4j;
import mj.scott.back.base.exception.ServiceException;
import mj.scott.back.base.response.StatusCode;
import mj.scott.back.user.mapper.UserMapper;
import mj.scott.back.user.pojo.dto.UserLoginParam;
import mj.scott.back.user.pojo.vo.UserVO;
import mj.scott.back.user.service.UserService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public UserVO login(UserLoginParam param) {
        log.debug("【业务层】【用户登录】{}",param);
        String username = param.getUsername();
        UserVO vo = userMapper.selectByUsername(username);
        if (vo == null){
            throw new ServiceException(StatusCode.USERNAME_ERROR);
        }
        if(!vo.getPassword().equals(param.getPassword())){
            throw new ServiceException(StatusCode.PASSWORD_ERROR);
        }
        log.debug("【业务层】【用户登录】{}",vo);
        return vo;
    }
}
